//
//  HSReverseGeocoderManager.m
//  HipalSports
//
//  Created by HiPal Sports on 14-4-10.
//  Copyright (c) 2014年 HipalSports. All rights reserved.
//

#import "HSReverseGeocoderManager.h"

@implementation HSReverseGeocoderManager

- (id)init
{
    self = [super init];
    if(self){
        
        
    }
    return self;
}

//单例
+(HSReverseGeocoderManager *)instance
{
    static HSReverseGeocoderManager *inst = nil;
    if(inst == nil){
        inst = [[HSReverseGeocoderManager alloc] init];
    }
    return inst;
    
}
//根据坐标，来反转地理位置，国家码等
- (void)reverseGeocoderWithCoordinate:(CLLocation *)newLocation
{
    
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder  reverseGeocodeLocation: newLocation completionHandler:
     ^(NSArray *placemarks, NSError *error) {
         
         if (placemarks &&  placemarks.count > 0) {
             
             CLPlacemark *placemark = [placemarks objectAtIndex:0];
             
             if (_delegate && [_delegate respondsToSelector:@selector(reverseGeocodeLocation:)]) {
                 [_delegate reverseGeocodeLocation:placemark];
             }
             
             
         }
     }];
}

- (void)geocodeAddressString:(NSString *)address {
    if (address==nil || address.length <1) {
        return;
    }
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder geocodeAddressString:address completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
        if (_delegate && [_delegate respondsToSelector:@selector(geocodeAddressStringS:)]) {
            [_delegate geocodeAddressStringS:placemarks];
        }
    }];
}


@end
